package com.boot.learning.springsecurity;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.boot.learning.exception.BadRequestException;
import com.boot.learning.exception.NotFoundException;

import io.swagger.annotations.ApiOperation;

/**
 * 测试security的访问限制
 * 
 * @since JDK1.8
 * @author vencano
 * @date 2017年1月8日 下午12:32:27
 */
@Controller
public class HelloSecurityController {

    @RequestMapping(value="/",method=RequestMethod.GET)
    @ApiOperation(value="首页")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/hello",method=RequestMethod.GET)
    @ApiOperation(value="欢迎")
    public String hello() {
        return "hello";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    @ApiOperation(value="登陆")
    public String login() {
        return "login";
    }
    
    @RequestMapping(value = "/home", method = RequestMethod.GET)
    @ApiOperation(value="主页")
    public String home() {
    	return "home";
    }
    
    @GetMapping("/mock/exception")
    @ApiOperation(value="模拟异常处理（返回页面形式）", notes="模拟500异常的处理机制")
    public String mockException() throws BadRequestException{
    	throw new BadRequestException( "这是一个模拟500的错误请求" );
    }
    
    @GetMapping("/mock/exception/json")
    @ApiOperation(value="模拟异常处理（返回json形式）",notes="模拟404异常的处理机制")
    public String mockExceptionJson() throws NotFoundException{
    	throw new NotFoundException( "这是一个模拟404的错误请求(返回json格式)" );
    }

}